<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import Pagination from "@/components/Pagination/index.vue";
  import xmDatePicker from '@/components/xmDatePicker/index.vue';

  const action = reactive({
    total:0,
    list:[] as any[],
    timeObj:getPlayEndTime(getDateArray('ymd'))
  })
  const listQuery = reactive({
    page: 1,
    limit: 20,
    from_user_id:'',
    to_user:'',
    gift_ids:''
  })
  const handleFilter = ()=>{
    listQuery.page = 1
    action.list = []
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const { playTime:startDate='', endTime:endDate='' } = action.timeObj
    const res = await statisticsApi.sdj2023Giftdetails({
      startDate,
      endDate,
      ...listQuery
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">送礼人UUID：</div>
          <el-input class="xm-width200" v-model="listQuery.from_user_id" placeholder="请输入UUID逗号分隔" />
        </div>
        <div class="labelItem">
          <div class="label">收礼人UUID：</div>
          <el-input class="xm-width200" v-model="listQuery.to_user" placeholder="请输入UUID逗号分隔" />
        </div>
        <div class="labelItem">
          <div class="label">礼物id：</div>
          <el-input class="xm-width200" v-model="listQuery.gift_ids" placeholder="请输入礼物id逗号分隔" />
        </div>
        <xmDatePicker
          type="daterange"
          v-model:timeval="action.timeObj" />
        <div class="labelItem">
          <el-button type="primary" @click="handleFilter">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="180" prop="date" label="日期" />
      <el-table-column width="100" prop="user_id" label="收礼人id" />
      <el-table-column width="100" prop="from_user_id" label="送礼人id" />
      <el-table-column width="100" prop="gift_id" label="礼物id" />
      <el-table-column min-width="140" prop="gift_name" label="礼物名称" />
      <el-table-column min-width="100" prop="gift_type" label="礼物类型">
        <template #default="scoped">
          {{ ['','普通礼物','幸运礼物'][scoped.row.type] }}
        </template>
      </el-table-column>
      <el-table-column min-width="100" prop="type" label="送出场景">
        <template #default="scoped">
          {{ ['','礼物栏','背包'][scoped.row.type] }}
        </template>
      </el-table-column>
      <el-table-column width="100" prop="gift_num" label="礼物数量" />
      <el-table-column width="100" prop="gift_price" label="礼物单价" />
      <el-table-column width="100" prop="total" label="礼物消耗" />

    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>